//
//  UIView+ToastView.m
//  YWBaseFrameWork
//
//  Created by 余伟 on 2017/2/5.
//  Copyright © 2017年 NeiQuan. All rights reserved.
//

#import "UIView+ToastView.h"
#import "YeeToastView.h"
#include <objc/runtime.h>

static  const  void  *YeeUIToastView =&YeeUIToastView;
static  NSString *YFailString  = @"tmall_notice_failed";
static  NSString *YNetString   = @"tmall_notice_info";
static  NSString *YSucString   = @"tmall_notice_success";

@implementation UIView (ToastView)
-(void)showToastlodingMessage:(NSString *)lodingMessage
{
    YeeToastView *toast=[self showMessage:lodingMessage imageName:YFailString];
    [toast.msgImageView setHidden:YES];
    [toast.activityIndicatorView setHidden:NO];
    [toast.activityIndicatorView startAnimating];
    [self addSubview:toast];
}
//修改更改图片和loding的位置
-(void)showToastErrorMessage:(NSString *)errorMessage
{
    YeeToastView *toast=[self  showMessage:errorMessage imageName:YFailString];
    [toast.activityIndicatorView setHidden:YES];
    [toast.activityIndicatorView stopAnimating];
    [toast.msgImageView setHidden:NO];
    [self addSubview:toast];
}
-(void)showToastNetErrorMessage:(NSString *)netErrorMessage
{
    YeeToastView *toast=[self  showMessage:netErrorMessage imageName:YNetString];
    [toast.activityIndicatorView setHidden:YES];
    [toast.activityIndicatorView stopAnimating];
    [toast.msgImageView setHidden:NO];
    [self addSubview:toast];
    
}
-(void)showToastSuccessMessage:(NSString *)successMessage
{
    YeeToastView *toast=[self  showMessage:successMessage imageName:YSucString];
    [toast.activityIndicatorView setHidden:YES];
    [toast.activityIndicatorView stopAnimating];
    [toast.msgImageView setHidden:NO];
    [self addSubview:toast];
    
}

-(void)showToastSuccessMessage:(NSString *)successMessage finish:(finish)block
{
    YeeToastView *toast=[self  showMessage:successMessage imageName:YSucString];
    [toast.activityIndicatorView setHidden:YES];
    [toast.activityIndicatorView stopAnimating];
    [toast.msgImageView setHidden:NO];
    [self addSubview:toast];
    
}
#pragma mark 创建对象
//需要考虑同一个对象上的toastView
-(YeeToastView*)showMessage:(NSString *)message imageName:(NSString *)imageName
{
    YeeToastView *toast= [[YeeToastView alloc] initWithFrame:self.bounds];
    toast.msglable.text=message;
    [toast.msgImageView setImage:[UIImage imageNamed:imageName]];
    return toast;
}
-(void)removeToastView
{
    if ([self ToastView])
    {
        [[self ToastView] removeFromSuperview];
    }
}
-(YeeToastView*)ToastView
{
    return objc_getAssociatedObject(self, YeeUIToastView);
}
-(void)setLodinggView:(YeeToastView*)ToastView
{
    objc_setAssociatedObject(self, YeeUIToastView, ToastView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
